package com.turbo.cloud.utils;

import cn.hutool.json.JSONUtil;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;
import java.util.Map;

public class TestCC {
    public static void main(String[] args) {
        String vins[] =
                { "LVBV3JBB8LY500658","LVBV3JBB1LY100263","LVBV3JBB7LY100266","LVBV3JBB3LY503158","LVBV3JBB1LW030453"
                        ,"LVBV3JBB3LW016750","LVBV3JBB1LW016746","LVBV3JBB5LY500648","LVBV3JBB2LW650986","LVBV3JBB3LW016747","LVBV3JBB9LY107834","LVBV3JBB1LW033501","LVBV3JBB3LY500664","LVBV3JBB2LY107836","LVBV3JBB6LY054414","LVBV3JBB7LY107833","LVBV3JBB1LY054417","LVBV3JBB2LW024354","LVBV3JBB2LY068665","LVBV3JBB0MY400068","LVBV3JBB5MY400065","LVBV3JBB3MY400064","LVBV3JBB9MY400070","LVBV3JBB2MY400122","LVBV3JBB2MY400119","LVBV3JBB5LY107832","LVBV3JBB4LY107840","LVBV3JBB9LY503178","LVBV3JBB6LY107838","LVBV3JBB9LY503164","LVBV3JBB9MY400067","LVBV3JBB8MY400299","LVBV3JBB6MY400303","LVBV3JBB5MY400230","LVBV3JBB7MY400231","LVBV3JBB7MY400181","LVBV3JBB0MY400121","LVBV3JBB7LW654466","LVBV3JBB6LY503171","LVBV3JBB9MY400277","LVBV3JBB7MY400259","LVBV3JBB1MY400614","LVBV3JBB5MY400714","LVBV3JBB2MY400671","LVBV3JBB1MY400256","LVBV3JBB6MY400284","LVBV3JBBXMY400725","LVBV3JBB8LW654461","LVBV3JBB0LW041377","LVBV3JBB0LY503215","LVBV3JBB2LW041378","LVBV3JBB3LY503225","LVBV3JBB2MY011514","LVBV3JBB5LY111945","LVBV3JBBXMY011521","LVBV3JBB8MY012358","LVBV3JBB6LY503204","LVBV3JBB5MY011524","LVBV3JBB6LY503218","LVBV3JBB2LY503166","LVBV3JBB5MY400020","LVBV3JBB0LY107835","LVBV3JBB6MY400771","LVBV3JBBXLY111942","LVBV6PDC8LW083053","LVBV3JBB4MY502330","LVBV3JBB0MY400118","LVBV3JBB6MY400253","LVBV3JBB9MY003491","LVBV3JBB2MY500141","LVBV3JBB5MY400762","LVBV3JBB1MY500146","LVBV3JBB7MY400732","LVBV3JBB8MY400724","LVBV3JBB4MY500125","LVBV3JBB4MY500075","LVBV3JBB9MY500072","LVBV3JBB7MY400715","LVBV3JBB3MY400260","LVBV3JBB5MY400261","LVBV3JBB8MY500094","LVBV3JBB1MY012363","LVBV3JBB9MY011543","LVBV3JBB8MY500273","LVBV3JBB6MY500272","LVBV3JBB9MY500248","LVBV3JBB9MY012370","LVBV3JBB3MY011537","LVBV3JBB7MY011542","LVBV3JBBXLY503206","LVBV3JBB0MY012354","LVBV3JBB4MY011305","LVBV3JBB1MY011309","LVBV3JBB3MY011523","LVBV3JBBXLY503173","LVBV3JBB4MY011515","LVBV3JBB6MY012360","LVBV3JBB1MY011519","LVBV3JBB3MY011540","LVBV3JBB8MY010948","LVBV3JBB5LY503159","LVBV3JBB4MY011529","LVBV3JBB8MY011310","LVBV3JBB5MY011541","LVBV3JBB6LY503168","LVBV3JBB9MY011302","LVBV6PDC6LW083052","LVBV3JBB2MY429720","LVBV3JBB9MY028746","LVBV3JBB3MY500116","LVBV3JBB6MY500093","LVBV3JBB8MY040001","LVBV3JBB4MY500089","LVBV3JBB5MY039940","LVBV3JBB1MY500082","LVBV3JBB8MY039950","LVBV3JBB2MY039958","LVBV3JBB5MY500084","LVBV3JBB1MY400757","LVBV3JBB3MY400663","LVBV3JBB5MY003651","LVBV3JBBXMY003645","LVBV3JBB6MY003481","LVBV3JBB7MY400651","LVBV3JBB4MY400719","LVBV3JBB0MY400734","LVBV3JBB5MY400650","LVBV3JBB8MY003482","LVBV3JBB2MW113990","LVBV3JBB6MY012391","LVBV3JBBXLY095547","LVBV3JBB1LY503224","LVBV3JBB6MW113975","LVBV3JBB6MY011533","LVBV3JBBXMY012362","LVBV3JBB6MY011516","LVBV3JBB8MW113993","LVBV3JBB9MY012367","LVBV3JBB7MY011525","LVBV3JBB0LY503179","LVBV3JBB5MY012396","LVBV3JBB0MY500249","LVBV3JBBXMY012359","LVBV3JBBXMW113963","LVBV3JBBXMY011535","LVBV3JBB9MY012353","LVBV3JBB7LY503180","LVBV3JBB1MW113981","LVBV3JBB8MY011520","LVBV3JBB9MY011526","LVBV3JBB2MY011304","LVBV3JBB5MY012365","LVBV3JBB0MY400748","LVBV3JBB7MW651519","LVBV3JBB6LW144027","LVBV3JBB6MY430045","LVBV3JBB9MY039925","LVBV3JBB9MY039956","LVBV3JBB2MY039961","LVBV3JBB5MY500120","LVBV3JBB0MY039960","LVBV3JBB9MY400649","LVBV3JBB3LY002447","LVBV3JBB7MY400682","LVBV3JBB7MY500264","LVBV3JBB5MY500263","LVBV3JBB9LY503228","LVBV3JBB0MY011527","LVBV3JBB0MY012368","LVBV3JBB0MY500266","LVBV3JBB7MY500278","LVBV3JBB4LW041379","LVBV3JBB5MY011314","LVBV3JBB2MY500270","LVBV3JBB3MY500276","LVBV3JBB7MY012397","LVBV3JBB8LY503172","LVBV3JBB2LW041381","LVBV3JBB1MY049672","LVBV3JBB5ME036618","LVBV3JBB4ME036819","LVBV3JBB1ME036812","LVBV3JBB3ME036813","LVBV3JBB5MY047519","LVBV3JBB0MY485428","LVBV3JBBXMY485517","LVBV3JBB6MY047674","LVBV3JBB5MY047715","LVBV3JBB0MY485557","LVBV3JBBXMY043594","LVBV3JBB2MY047686","LVBV3JBBXMY485372","LVBV3JBB4MY485481","LVBV3JBB8MY047689","LVBV3JBB1MY485499","LVBV3JBB1MY485521","LVBV3JBB5MY047701","LVBV3JBB4MY485447","LVBV3JBB0MY485512","LVBV3JBBXMY039951","LVBV3JBB3MY039970","LVBV3JBB1MY039983","LVBV3JBB9MY003474","LVBV3JBB7MW113984","LVBV3JBB9MY500265","LVBV3JBB0MW113955","LVBV3JBB4LW041382","LVBV3JBB9MY011316","LVBV3JBBXMY011518","LVBV3JBBXMY500274","LVBV3JBB1MY431488","LVBV3JBB3MY043596","LVBV3JBB0MY047704","LVBV3JBB9MY043599","LVBV3JBB1MY043595","LVBV3JBB4MY043591","LVBV3JBB8MY047658","LVBV3JBB1MY047484","LVBV3JBB7MY043598","LVBV3JBB1MY043600","LVBV3JBB3MY047521","LVBV3JBB5MY043597","LVBV3JBBXMY400692","LVBV3JBB6MY012357","LVBV3JBBXMY500257","LVBV3JBB4MY011532","LVBV3JBB3LY111944","LVBV3JBB5MY055653","LVBV3JBB6MY049540","LVBV3JBB5MY485201","LVBV3JBB3MY056641","LVBV3JBB9ME036816","LVBV3JBB2ME036818","LVBV3JBB7ME036815","LVBV3JBB2MY047672","LVBV3JBB1MY050188","LVBV3JBB2MY485527","LVBV3JBB1MY050224","LVBV3JBBXMY050223","LVBV3JBB7MY485524","LVBV3JBB1MY047467","LVBV3JBB3MY050225","LVBV3JBB2MY485429","LVBV3JBB8MY050222","LVBV3JBB5MY485487","LVBV3JBB3MY485486","LVBV3JBB6MY485482","LVBV3JBB0MY047718","LVBV3JBB6MY485515","LVBV3JBB0MY485493","LVBV3JBBXMY485520","LVBV3JBB1MY050210","LVBV3JBB9MY050214","LVBV3JBB6MY504919","LVBV3JBB3MY047504","LVBV3JBBXMY047659","LVBV3JBB2MY047655","LVBV3JBB0MY485526","LVBV3JBB4MY485528","LVBV3JBB6MY047657","LVBV3JBBXMY485484" };

        //String vins[] = {"LVBV3JBB8LY500658"};
        String url = "https://cls.ca-sinfusi.com/pre-term/gateway/cls-ms-lease/webservice/om-order-carbases/findCarPriceByVin/";
        String cookie = "scg=32469e00dc2e42eda21fb383920b6800; access_token=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJwd2RTdHJlbmd0aCI6MiwidXNlcl9uYW1lIjoiYWRtaW4iLCJ1c2VyU291cmNlIjoib3RoZXIiLCJzY29wZSI6WyJvcGVuaWQiXSwiZXhwIjoxNjc2MzY4MjY0LCJpYXQiOjE2NzYzNjY3NjQsIm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TQxIiwiUk9MRV9DTFMiLCIzNzViMmMxYmUzOGY2YTNlYTUwM2YxYjg5M2E1MGVjNSIsIlJPTEVfVVNFUiJdLCJqdGkiOiIzMjE3MWViMy1jZTU0LTQ1ZDgtOGY2MC1kYzI0MDBlMzgzODMiLCJwd2RTdHJlbmd0aE5hbWUiOiJTVFJPTkciLCJjbGllbnRfaWQiOiJ3ZWJfYXBwIn0.ZA9BT4hIVqa5x-BtqOcrYzQZnw11APw3hNWOfCWyVgKapKxAhizdND9oaUsaXbawOhNT1GdB40vSQsql7vVzGMWsYSV2oFz206Bo9ukMFMcgZ2KT-FlhROAsWZdR0f4vJMnoxE_4NM3qzWhipQucaRSnUgqkzRVu0bQUBrGmaWviUfP2hureVxCBDwELGQYK5jTglnRD6WAg5Frj7PVrGOJwmEIeG5l7ZNsB_MGxXpDxdnMoxHWBv1f7OMLWhkkh1FS3REOSkGDis_gEhPKf81ct7JbBWho08WP1V5wS2_6lXoB4qspifzIKQnUOQ2Xvdz79b4ACBqGJjzVkXS2ndQ; x-client-id=CLIENT-DGS7KXP59C6003JE";
        for (String vin : vins) {
            String resultJson = sendGet(url + vin, cookie);
            //System.out.println("请求结果：" + resultJson);
            Map result;

            String exFactoryPrice = "";
            String salePrice = "";
            String lastRunDate = "";
            try {
                result = JSONUtil.toBean(resultJson, Map.class);
                exFactoryPrice = ((Map) (((Map) result.get("data")).get("carPriceCarInfoDTO"))).get("exFactoryPrice").toString();
                salePrice = ((Map) (((Map) result.get("data")).get("carPriceCarInfoDTO"))).get("salePrice").toString();
                lastRunDate = ((Map) (((Map) result.get("data")).get("carPriceSaleInfo"))).get("lastRunDate").toString();
            } catch (Exception e) {

            }

            System.out.println(vin + "," + exFactoryPrice + "," + salePrice + "," + lastRunDate);

            // exFactoryPrice 标准出厂价格
            // salePrice 整车价格总计（除运费）
        }


    }

    public static String sendGet(String url, String cookie) {
        String result = "";
        BufferedReader in = null;
        try {
            String urlNameString = url;
            URL realUrl = new URL(urlNameString);
            // 打开和URL之间的连接
            URLConnection connection = realUrl.openConnection();
            // 设置通用的请求属性
            connection.setRequestProperty("accept", "*/*");
            connection.setRequestProperty("connection", "Keep-Alive");
            connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");

            connection.setRequestProperty("Cookie", cookie);
            // 建立实际的连接
            connection.connect();
            // 获取所有响应头字段
            Map<String, List<String>> map = connection.getHeaderFields();
            // 定义 BufferedReader输入流来读取URL的响应
            in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String line;
            while ((line = in.readLine()) != null) {
                result += line;
            }
        } catch (Exception e) {
            //System.out.println("发送GET请求出现异常！" + e);
            //e.printStackTrace();
        }
        // 使用finally块来关闭输入流
        finally {
            try {
                if (in != null) {
                    in.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        return result;
    }
}
